import { Body, Controller, Get, Post, Res, Session } from "@nestjs/common"
import { AdministratorService } from "./administrator.service"
import { Response } from "express"

@Controller("/admin")
export class AdministratorController {
  constructor(private readonly administratorService: AdministratorService) {}

  // Generate captcha
  @Get("/generateCaptcha")
  async generateCaptcha(
    @Res() res: Response,
    @Session() session: object
  ): Promise<void> {
    return await this.administratorService.generateCaptcha(res, session)
  }

  // Login
  @Post("/login")
  async login(
    @Body() body: object,
    @Session() session: object,
    @Res() res: Response
  ): Promise<void> {
    return await this.administratorService.login(body, session, res)
  }

  // Logout
  @Post("/logout")
  async logout(
    @Session() session: object,
    @Res() res: Response
  ): Promise<void> {
    return await this.administratorService.logout(session, res)
  }

  // Modifying password
  @Post("/updateAccount")
  async update(@Body() body: object, @Res() res: Response): Promise<void> {
    return await this.administratorService.updateAccount(body, res)
  }

  // Obtain account information
  @Get("/getInfo")
  async getInfo(@Res() res: Response): Promise<void> {
    return await this.administratorService.getInfo(res)
  }

  // Reset password
  @Post("/reset")
  async reset(
    @Body() body: object,
    @Res() res: Response,
    @Session() session: object
  ): Promise<void> {
    return this.administratorService.reset(body, res, session)
  }
}
